/**
 * 
 */
package cu.ds.logicalsync.fytasrealm.communication;

import java.util.HashSet;
import java.util.Set;

import cu.ds.logicalsync.fytasrealm.communication.event.MapStatusListener;
import cu.ds.logicalsync.fytasrealm.communication.event.WorldStatusListener;
import cu.ds.logicalsync.fytasrealm.communication.model.PeerInfo;
import cu.ds.logicalsync.fytasrealm.model.World;

/**
 * @author r.vashira
 *
 */
public class WorldStatusService implements WorldStatusServiceProvider {
	
	/** Member Variables **/
	private JxtaConnection connection;
	
	/**
     * The table of peer status listeners.
     */
    private Set<WorldStatusListener> listeners = new HashSet<WorldStatusListener>();
    
    /**
	 * @param connection
	 */
	public WorldStatusService(JxtaConnection connection) {
		super();
		this.connection = connection;
		
		//TODO: Create MessageSender and Receiver for WorldStatusService
	}
	  

	/**
	 * {@inheritDoc} 
	 */
	public synchronized void addListener(WorldStatusListener listener) {
		listeners.add(listener);
	}

	/**
	 * {@inheritDoc} 
	 */
	public boolean enterWorld(PeerInfo requestor, PeerInfo host, World worldToEntered) {
		boolean isAllowed = false;
		// TODO: requestWorldEnter <-- inputPipe, then update isAllowed in outputPipe
		isAllowed = true;
		
		return isAllowed;
	}
	
	/**
	 * {@inheritDoc} 
	 */
	public void leaveWorld(PeerInfo requestor, PeerInfo host,
			World worldToEntered) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * {@inheritDoc} 
	 */
	public boolean removeListener(WorldStatusListener listener) {
		return listeners.remove(listener);
	}

	/**
	 * {@inheritDoc} 
	 */
	public void start() {
		// TODO: run background service here, if any
	}

	/**
	 * {@inheritDoc} 
	 */
	public void stop() {
		// Should we release resources holding?
	}

}
